import aiohttp
import json
from config.config import settings

class DifyAPIQuery:
    def __init__(self):
        self.api_key = settings.dify_api_key
        self.url = settings.dify_url
        self.headers = {
            'Authorization': f'Bearer {settings.dify_api_key}',
            'Content-Type': 'application/json'
        }

    async def send_query(self, session, query, user):
        data = {
            "inputs": {},
            "query": query,
            "response_mode": "blocking",
            "conversation_id": "",
            "user": user
        }
        async with session.post(self.url, headers=self.headers, data=json.dumps(data)) as response:
            return await response.json()